From bd843d47d8a4dbab1b273420b52d3e3eb290df9b Mon Sep 17 00:00:00 2001 From: "cl349@firebug.cl.cam.ac.uk" Date: Mon, 12 Sep 2005 21:42:26 +0000 Subject: [PATCH] Always allow overriding where clients connect through XENSTORED_PATH. Detect if we're connecting to a socket or to the domain device and open accordingly. Signed-off-by: Christian Limpach --- tools/xenstore/xs.c | 19 ++++++++++++++++--- tools/xenstore/xs_lib.c | 30 ++++++++++++++++++++++++------ 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/tools/xenstore/xs.c b/tools/xenstore/xs.c index 95fc942c4a..9991cefc61 100644 --- a/tools/xenstore/xs.c +++ b/tools/xenstore/xs.c @@ -97,19 +97,32 @@ static struct xs_handle *get_dev(const char *connect_to) return NULL; } +static struct xs_handle *get_handle(const char *connect_to) +{ + struct stat buf; + + if (stat(connect_to, &buf) != 0) + return NULL; + + if (S_ISSOCK(buf.st_mode)) + return get_socket(connect_to); + else + return get_dev(connect_to); +} + struct xs_handle *xs_daemon_open(void) { - return get_socket(xs_daemon_socket()); + return get_handle(xs_daemon_socket()); } struct xs_handle *xs_daemon_open_readonly(void) { - return get_socket(xs_daemon_socket_ro()); + return get_handle(xs_daemon_socket_ro()); } struct xs_handle *xs_domain_open(void) { - return get_dev(xs_domain_dev()); + return get_handle(xs_domain_dev()); } void xs_daemon_close(struct xs_handle *h) diff --git a/tools/xenstore/xs_lib.c b/tools/xenstore/xs_lib.c index 4c355b9902..5eb7fada6e 100644 --- a/tools/xenstore/xs_lib.c +++ b/tools/xenstore/xs_lib.c @@ -38,37 +38,55 @@ static const char *xs_daemon_rundir(void) return (s ? s : "/var/run/xenstored"); } -const char *xs_daemon_socket(void) +static const char *xs_daemon_path(void) { static char buf[PATH_MAX]; - sprintf(buf, "%s/socket", xs_daemon_rundir()); + char *s = getenv("XENSTORED_PATH"); + if (s) + return s; + if (snprintf(buf, PATH_MAX, "%s/socket", + xs_daemon_rundir()) >= PATH_MAX) + return NULL; return buf; } +const char *xs_daemon_socket(void) +{ + return xs_daemon_path(); +} + const char *xs_daemon_socket_ro(void) { static char buf[PATH_MAX]; - sprintf(buf, "%s/socket_ro", xs_daemon_rundir()); + const char *s = xs_daemon_path(); + if (s == NULL) + return NULL; + if (snprintf(buf, PATH_MAX, "%s_ro", s) >= PATH_MAX) + return NULL; return buf; } const char *xs_daemon_store(void) { static char buf[PATH_MAX]; - sprintf(buf, "%s/store", xs_daemon_rootdir()); + if (snprintf(buf, PATH_MAX, "%s/store", + xs_daemon_rootdir()) >= PATH_MAX) + return NULL; return buf; } const char *xs_daemon_transactions(void) { static char buf[PATH_MAX]; - sprintf(buf, "%s/transactions", xs_daemon_rootdir()); + if (snprintf(buf, PATH_MAX, "%s/transactions", + xs_daemon_rootdir()) >= PATH_MAX) + return NULL; return buf; } const char *xs_domain_dev(void) { - char *s = getenv("XENSTORED_DOMAIN_DEV"); + char *s = getenv("XENSTORED_PATH"); return (s ? s : "/proc/xen/xenbus"); } -- 2.30.2